<?php
    // +----------------------------------------------------------------------
    // | Created by PHPstorm: JRKAdmin框架 [ JRKAdmin ] 
    // +----------------------------------------------------------------------
    // | Copyright (c) 2019~2022 [LuckyHHY] All rights reserved.
    // +----------------------------------------------------------------------
    // | SiteUrl: http://www.luckyhhy.cn
    // +----------------------------------------------------------------------
    // | Author: LuckyHhy <jackhhy520@qq.com>
    // +----------------------------------------------------------------------
    // | Date: 2020/3/4-15:15
    // +----------------------------------------------------------------------
    // | Description:  
    // +----------------------------------------------------------------------


    namespace app\admin\controller;


    use app\admin\model\Comments;
    use Jrk\Trees;
    use think\Exception;

    class Comment extends AdminBase
    {

        public function initialize()
        {
            parent::initialize(); // TODO: Change the autogenerated stub

            $this->model = app()->model("Comments");

            $this->assign("num",$this->model->where("is_ok",0)->count());
        }


        /**
         * @author: LuckyHhy <jackhhy520@qq.com>
         * @date: 2020/3/4
         * @name: checkComment
         * @describe:批量审核
         */
        public function checkComment()
        {
            if (IS_AJAX) {
                $ids = $this->request->post("ids");
                try {
                    $res = $this->model->checkComm($ids);
                    addLog("修改操作", "批量审核文章评论ID：".$ids);
                    if ($res) {
                        $this->success("操作成功");
                    } else {
                        $this->error("操作失败");
                    }
                } catch (Exception $exception) {

                    $this->error($exception->getMessage());
                }

            }
        }


        /**
         * @return mixed
         * @throws Exception
         * @throws \think\exception\PDOException
         * @author: LuckyHhy <jackhhy520@qq.com>
         * @date: 2020/3/12 0012
         * @name: del
         * @describe:
         */
        public function del(){
            $ids = $this->request->post("ids");

            $res=Trees::getChildrenPid(Comments::all(),$ids);

            /**
             * 有子评论一同删除
             */
            if(!empty($res)){
                $da=array_merge($res,[intval($ids)]);
            }else{
                $da=[intval($ids)];
            }
            //dump($da);
            addLog("删除操作", "删除文章评论ID：".@implode(",",$da));

            return $this->model->del($da);

        }


    }